var userInfo = null;
var prefixHttpUrl = 'http://127.0.0.1:8001';

/**
 * ajax工具js
 * @param pageUrl
 * @param jsonData
 * @param backFunc
 */
function requestPostAjax(url,status, jsonData, backFunc) {
    $.ajax({
        type : "POST",
        async : status,
        url :   url,
        data : jsonData,
        dataType:'json',
        xhrFields: {
            withCredentials: true
        },
        success : function(data) {
            //data =  JSON.parse(data);
            if (data.code === 403){
              //  alert(data.errMsg);
                window.location.href = '/login';
                return;
            }
            if (backFunc && $.isFunction(backFunc)) {
                backFunc(data);
            }
        }
    });
};

/**
 * 包含了上传文件功能,设置了下方的俩参数
 *  contentType: false,
 processData: false,
 * @param url
 * @param status
 * @param jsonData
 * @param backFunc
 */
function requestPostFileAjax(url,status, jsonData, backFunc) {
    $.ajax({
        type : "POST",
        async : status,
        url :   url,
        data : jsonData,
        dataType:'json',
        contentType: false,
        processData: false,
        xhrFields: {
            withCredentials: true
        },
        success : function(data) {
            //data =  JSON.parse(data);
            if (data.code === 403){
                //  alert(data.errMsg);
                window.location.href = '/login';
                return;
            }
            if (backFunc && $.isFunction(backFunc)) {
                backFunc(data);
            }
        }
    });
};

function requestGetAjax(url, backFunc) {
    $.ajax({
        type : "get",
        url :   url,
        xhrFields: {
            withCredentials: true
        },
        success : function(data) {
            data =  JSON.parse(data);
            if (data.code === 403){
            //    alert(data.errMsg);
                window.location.href = '/login';
                return;
            }
            if (backFunc && $.isFunction(backFunc)) {
                backFunc(data);
            }
        }
    });
};

function requestGetAjaxData(url,jsonData, backFunc) {
    $.ajax({
        type : "get",
        url :   url,
        data : jsonData,
        xhrFields: {
            withCredentials: true
        },
        success : function(data) {
            data =  JSON.parse(data);
            if (data.code === 403){
              //  alert(data.errMsg);
                window.location.href = '/login';
                return;
            }
            if (backFunc && $.isFunction(backFunc)) {
                backFunc(data);
            }
        }
    });
};

function upload(data) {
    if(FileTypeCheck()){
        if(data ==='project'){
            var urlfile = prefixHttpUrl + "/collection/importExcel";
        }else if(data==='person'){
            var urlfile = prefixHttpUrl + "/person/importExcel";
        }
        $("#form1").ajaxSubmit({
            type: 'post',
            url: urlfile,
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            xhrFields: {
                withCredentials: true
            },
            success: function(data){
                alert(data);

            },error: function(XmlHttpRequest, textStatus, errorThrown){
                alert(  '请检查Excel内容是否正确或者压缩包中是否含有异常文件');
            }
        });
    }
    //防止表单非ajax方式提交
    return false;
}

function quitUser() {
    var url = "/user/quitUser";
    requestGetAjax(url,function (resData) {
        if (200 === resData.code) {
            window.location.href = '/login';
        }else{
            alert(resData.errMsg);
        }
    });
}




function getStatusStr(text){

    if( text == 'temporary_state'){
        return "暂存";
    }else if( text == 'submit_state'){
        return "新建";
    }else if( text == 'success_state'){
        return "审核通过";
    }else if( text == 'reject_state'){
        return "审核拒绝";
    }else if( text == 'waitSupe_state'){
        return "待上级审核";
    }else if( text == 'waitBoss_state'){
        return "终审";
    }else if( text == 'unsubmit_state'){
        return "未提交";
    }else{
        return "未知";
    }
}